package com.ruoyi.lab.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lab.mapper.JacLabStandardMapper;
import com.ruoyi.lab.domain.JacLabStandard;
import com.ruoyi.lab.service.IJacLabStandardService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.transaction.annotation.Isolation;
/**
 * standardService业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-25
 */
@Service

public class JacLabStandardServiceImpl implements IJacLabStandardService 
{
    @Autowired
    private JacLabStandardMapper jacLabStandardMapper;
    public final String OK="1";
    /**
     * 查询standard
     * 
     * @param id standardID
     * @return standard
     */
    @Override
    public JacLabStandard selectJacLabStandardById(Long id)
    {
        return jacLabStandardMapper.selectJacLabStandardById(id);
    }

    /**
     * 查询standard列表
     * 
     * @param jacLabStandard standard
     * @return standard
     */
    @Override
    public List<JacLabStandard> selectJacLabStandardList(JacLabStandard jacLabStandard)
    {
        return jacLabStandardMapper.selectJacLabStandardList(jacLabStandard);
    }

    /**
     * 新增standard
     * 
     * @param jacLabStandard standard
     * @return 结果
     */
    @Override
    public int insertJacLabStandard(JacLabStandard jacLabStandard)
    {
        return jacLabStandardMapper.insertJacLabStandard(jacLabStandard);
    }

    /**
     * 修改standard
     * 
     * @param jacLabStandard standard
     * @return 结果
     */
    @Override
    public int updateJacLabStandard(JacLabStandard jacLabStandard)
    {
        return jacLabStandardMapper.updateJacLabStandard(jacLabStandard);
    }

    /**
     * 删除standard对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteJacLabStandardByIds(String ids)
    {
        return jacLabStandardMapper.deleteJacLabStandardByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除standard信息
     * 
     * @param id standardID
     * @return 结果
     */
    public int deleteJacLabStandardById(Long id)
    {
        return jacLabStandardMapper.deleteJacLabStandardById(id);
    }

    @Override

    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
    public String importFile(MultipartFile file) throws Exception
    {
        String result = OK;
        jacLabStandardMapper.deleteJacLabStandard();
        ExcelUtil<JacLabStandard> util = new ExcelUtil<>(JacLabStandard.class);
        List<JacLabStandard> lists = util.importExcel(file.getInputStream());
        for (JacLabStandard l:lists) {
                    try {
                        jacLabStandardMapper.insertJacLabStandard(l);
                    } catch (Exception e) {
                        result = "文件导入失败！";
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    }
                }
        return result;
    }
}
